/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

/**
 *
 * @author Ies Meulmeester
 */
/*
 * //1_5135.3768,N_00446.4666,E_---_VVV Breda_P2 coords.add(new GpsCoordinate(
 * new GpsLatitude(51, 35, 37.68), new GpsLongitude(4, 46, 46.66)));
 *
 *
 *
 * //18_5135.1960,N_00446.3176,E_---_Grote Kerk_P16,P17,P40,A1 coords.add(new
 * GpsCoordinate( new GpsLatitude(51, 35, 19.60), new GpsLongitude(4, 46,
 * 31.76)));
 */
public abstract class AbstractDistanceCalculator {

    public AbstractDistanceCalculator() {
    }

    public double getDistance(GpsCoordinate gpsCoordinateOne, GpsCoordinate gpsCoordinateTwo) {
        double rawDistMiles = calculateDistance(
                gpsCoordinateOne.getLatitude().getDecimal(),
                gpsCoordinateOne.getLongitude().getDecimal(),
                gpsCoordinateTwo.getLatitude().getDecimal(),
                gpsCoordinateTwo.getLongitude().getDecimal());
        return convert(rawDistMiles);
    }

    protected abstract double convert(double rawDistance);
    public abstract String getUnit();

    public double calculateDistance(double lat1, double lng1, double lat2, double lng2) {
        double earthRadius = 3958.75;
        double dLat = Math.toRadians(lat2 - lat1);
        double dLng = Math.toRadians(lng2 - lng1);
        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
                + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2))
                * Math.sin(dLng / 2) * Math.sin(dLng / 2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        double dist = earthRadius * c;
        return dist;
    }
}
